using System;
using System.Collections;
using System.Text;

namespace cuberga.Workflow
{
    public sealed class BlackBoard
    {
        static readonly private BlackBoard _instance = new BlackBoard();
        private Hashtable _hashTable;

        // Explicit static constructor to tell C# compiler
        // not to mark type as beforefieldinit
        static BlackBoard() {}
        BlackBoard()
        {
            _hashTable = new Hashtable();
        }
        
        public static BlackBoard Instance
        {
            get
            {
                return _instance;
            }
        }

        public Object Read(string name)
        {
            Console.WriteLine("[BB]->{0}", name);

            return _hashTable[name];
        }

        public void Write(string name, object objectRef)
        {
            Console.WriteLine("[BB]<-{0}",name);

            if (_hashTable.ContainsKey(name))
            {
                _hashTable.Remove(name);
            }

            _hashTable.Add(name, objectRef);
        }
    }
}
